package edu.biwu.Cookie01;

import edu.biwu.utils.CookieUtils;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet("/deleteCookie")
public class DeleteCookie extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //首先我们要获取要删除的cookie

        Cookie cookie = CookieUtils.getCookie(request.getCookies(), "id");
        System.out.println(request.getCookies());
        if (cookie!=null){
            System.out.println("1111111111111");
            //删除这个cookie
            cookie.setMaxAge(0);
            cookie.setPath("/day07");
            response.addCookie(cookie);//指挥浏览器删除指定的cookie
        }else {
            response.setContentType("text/html;charset=UTF-8");
            response.getWriter().write("Cookie不存在");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
